//
//  RCDCornerBtn.m
//  jsy
//
//  Created by  任辰东 on 2020/4/13.
//  Copyright © 2020 JSY. All rights reserved.
//

#import "RCDCornerBtn.h"
#import "UIView+CutViewRadius.h"

@interface RCDCornerBtn ()

@end

@implementation RCDCornerBtn

- (void)drawRect:(CGRect)rect {
    // Drawing code
    //切圆角
    [self cutViewRadiusAndRadiusSize:self.cornerRadius];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViews];
        self.cornerRadius = 20;
        
    }
    return self;
}

- (void)setupViews
{
    self.backgroundColor = UIColorFromHex(kColorMain);
    [self setTitleColor:UIColorFromHex(0xffffff) forState:UIControlStateNormal];
    [self addTarget:self action:@selector(clickAction:) forControlEvents:UIControlEventTouchUpInside];
    [self setTitleFont:18];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    
    WeakSelf
    [RACObserve(self, enabled) subscribeNext:^(NSNumber *x) {
        StrongSelf
        self.alpha = x.boolValue ? 1 : 0.5;
    }];
}


- (void)clickAction:(UIButton *)button
{
    if (self.clickBlock) {
        self.clickBlock(self);
    }
}

- (void)setTitleString:(NSString *)string
{
    [self setTitle:string forState:UIControlStateNormal];
}

- (void)setTitleFont:(CGFloat)font
{
    self.titleLabel.font = UIFontSize(font);
}

- (void)setTitleColor:(UIColor *)color
{
    [self setTitleColor:color forState:UIControlStateNormal];
}


@end
